Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make the Debugger a singleton and do not reset the stopframe to None during postmortem. #667

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

hwalinga
Copy link

This fixes #607. Making the Debugger a singleton should be enough to fix #607. HOWEVER, pytest def postmortem() calls .reset() which resets the stopframe. Somehow, this causes the debugger to stop somewhere inside internal debugger source code, instead of in the code the postmortem should be done.

So, this also includes an override of the .reset() method and detects when the debugger is already running and does not reset the stopframe. See also #67.

…during postmortem.

This fixes inducer#607. Making the Debugger a singleton should be enough to fix inducer#607.
HOWEVER, pytest def postmortem() calls .reset() which resets the stopframe.
Somehow, this causes the debugger to stop somewhere inside internal debugger source code,
instead of in the code the postmortem should be done.

So, this also includes an override of the .reset() method and detects when the debugger
is already running and does not reset the stopframe. See also inducer#67.
@hwalinga
Copy link
Author

Reproduce issue.

Install pytest and pudb.

test.py:

def test_foo():
    breakpoint()
    raise Exception
pytest --pdbcls pudb.debugger:Debugger --pdb --capture=no test.py

NB. The stopframe issue (#52) can also be observed with pytest-pudb using

pytest --pudb test.py

Copy link
Owner

@inducer inducer left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks. Some comments below.

Comment on lines +241 to +250
import linecache
linecache.checkcache()
self.botframe = None
if not self._pytest_postmortem:
self.stopframe = None
else:
self._pytest_postmortem = False
self.returnframe = None
self.quitting = False
self.stoplineno = 0
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be possible to call into Bdb.reset for some of this? We're already copy-pasting too much of Bdb's guts into pudb... (If not, add a comment why not.)

Comment on lines 223 to 224
# Okay, now we have a debugger
self._current_debugger.append(self)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could we get rid of _current_debugger in favor of the singleton mechanism?

Override from Bdb.reset()
When pytest starts a postmortem analysis, but the debugger is already active,
calling .reset() in src/_pytest/debugging.py::post_mortem
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add Github link to specific version?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

"Debugger instance already exists" when used in pytest
2 participants